﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Tools;
using Tour.DAL;

namespace Tour.BLL
{
    /// <summary>
    /// Summary description for LocaleStringResource
    /// </summary>
    public class LocaleStringResourceManagerBase
    {
        public LocaleStringResourceManagerBase()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public void InsertUpdate(LocaleStringResourceEntity item)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@LanguageID", item.LanguageID));
            ls.Add(new SqlParameter("@ResourceName", item.ResourceName));
            ls.Add(new SqlParameter("@ResourceValue", item.ResourceValue));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_InsertUpdateLocaleStringResource", sqlparam);
        }
        public void InsertUpdate(int LanguageID, string ResourceName, string ResourceValue)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@LanguageID", LanguageID));
            ls.Add(new SqlParameter("@ResourceName", ResourceName));
            ls.Add(new SqlParameter("@ResourceValue", ResourceValue));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_InsertUpdateLocaleStringResource", sqlparam);
        }
        public void Delete(int LanguageID,string ResourceName)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@LanguageID", LanguageID));
            ls.Add(new SqlParameter("@ResourceName", ResourceName));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_DeleteLocaleStringResource", sqlparam);
        }
        public LocaleStringResourceEntity GetLocaleStringResourceEntity(DataRow dr)
        {
            LocaleStringResourceEntity item = new LocaleStringResourceEntity();            
            if (dr.Table.Columns.Contains("LanguageID"))
                item.LanguageID = dr["LanguageID"].ToInt();              
            if (dr.Table.Columns.Contains("ResourceName"))
                item.ResourceName = dr["ResourceName"].ToString();              
            if (dr.Table.Columns.Contains("ResourceValue"))
                item.ResourceValue = dr["ResourceValue"].ToString();              
            return item;
        }        
        public DataTable SelectOneRDT(int LanguageID,string ResourceName)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@LanguageID", LanguageID));
            ls.Add(new SqlParameter("@ResourceName", ResourceName));
            SqlParameter[] sqlparam = ls.ToArray();
            return SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectLocaleStringResource", sqlparam);
        }
        public LocaleStringResourceEntity SelectOne(int LanguageID,string ResourceName)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@LanguageID", LanguageID));
            ls.Add(new SqlParameter("@ResourceName", ResourceName));
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectLocaleStringResource", sqlparam);
            if(dt!=null && dt.Rows.Count>0)
                return GetLocaleStringResourceEntity(dt.Rows[0]);
            return null;
        }
        public DataTable SelectAllRDT()
        {
            return SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectLocaleStringResourcesAll", null);
        }
        public List<LocaleStringResourceEntity> SelectAll()
        {
            List<LocaleStringResourceEntity> lsresult= new List<LocaleStringResourceEntity>();
            DataTable dt =  SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectLocaleStringResourcesAll", null);
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetLocaleStringResourceEntity(dt.Rows[i]));            
            return lsresult;
        }
    }
}

